<%@ page import="com.beerandjesus.photogallery.image.PhotoGalleryImage" %>
<%@ page import="com.beerandjesus.photogallery.page.PhotoGalleryPage" %>
<%@ page import="com.beerandjesus.photogallery.page.PhotoGalleryPageFactory" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>

<%
    PhotoGalleryPageFactory factory = (PhotoGalleryPageFactory) WebApplicationContextUtils.
            getWebApplicationContext(config.getServletContext()).getBean("pageFactory");
    PhotoGalleryPage pg = factory.getPage(request);
%>
<html>
<head>
    <title><%=pg.getTitle()%>
    </title>
    <link href="/css/photogallery.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="navLinksBorders">
    <div class="navLinks">
        <h1><%= pg.getTitle() %>
        </h1>

    </div>
</div>

<div class="thumbnails">
    <div class="row">
        <%
            // Print images
            String thumbUri;
            String pictureUri;
            int count = 0;
            while (pg.hasNext()) {
                PhotoGalleryImage image = pg.next();
                thumbUri = image.getThumbUri();
                pictureUri = image.getPictureUri();
                if (thumbUri != null) {
                    out.println("<a href=\"" + pictureUri + "\"><img src=\"" +
                            thumbUri + "\"></a>");
                } else {
                    out.println("<img src=\"" + pictureUri + "\">");
                }
                count++;
                if (count % 4 == 0) {
                    out.println("<div style=\"clear: both;\">&nbsp;</div>");
                    out.println("</div>");
                    if (count < 16) {
                        out.println("<div class=\"row\">");
                    }
                }
            }
        %>
    </div>
</div>
<div class="navLinksBorders">
    <div class="navLinks">

    </div>
</div>
</body>
</html>